<template>
  <el-container class="tab-container">
    <el-main class="main">
      <collapse-tab class="main-search">
        <el-form
          :inline="true"
          :model="queryCondition"
          label-width="80px"
          @keyup.enter.native="query"
        >
          <!--查询条件区 -->
          <el-form-item label="日志类型">
            <dictionary-select
              v-model="queryCondition.logType"
              multiple
              :code="constant.DICTIONARY_TYPE_CODES.LOG_TYPE"
              class="form-item"
            />
          </el-form-item>
          <el-form-item label="操作">
            <p-input v-model="queryCondition.content" class="form-item" />
          </el-form-item>
          <el-form-item label="姓名">
            <p-input v-model="queryCondition.operatorName" class="form-item" />
          </el-form-item>
          <el-form-item label="账号">
            <p-input v-model="queryCondition.operatorAccount" class="form-item" />
          </el-form-item>
          <el-form-item label="ip">
            <p-input v-model="queryCondition.operatorIp" class="form-item" />
          </el-form-item>
          <el-form-item label="请求参数">
            <p-input v-model="queryCondition.requestParam" class="form-item" />
          </el-form-item>

          <el-form-item label="日志时间">
            <el-date-picker
              v-model="queryCondition.requestTimeBeginForQuery"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="date"
              align="right"
              unlink-panels
              placeholder="开始日期"
              class="form-item"
            />
          </el-form-item>
          <el-form-item label="至">
            <el-date-picker
              v-model="queryCondition.requestTimeEndForQuery"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="date"
              align="right"
              unlink-panels
              placeholder="结束日期"
              class="form-item"
            />
          </el-form-item>
          <el-form-item style="float:right;">
            <list-button-query :page-code="pageCode" />
          </el-form-item>
          <div class="clearfix" />
        </el-form>
      </collapse-tab>
      <el-card class="main-report">
        <div>
          <list-button-refresh :page-code="pageCode" />
          <list-button-add :page-code="pageCode" />
          <list-button-remove :page-code="pageCode" />
          <div style="clear:both;" />
        </div>
        <div style="margin-top:5px;">
          <div>
            <columns-controller v-model="columnList" :table-key="tableKey" />
          </div>
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%"
            highlight-current-row
            border
            @sort-change="handleSortChange"
            @current-change="handleRowChange"
            @selection-change="handleSelectionChange"
            @row-dblclick="handleDoubleClickRow"
          >
            <el-table-column type="selection" width="55" />
            <el-table-column
              v-for="(item, index) in showCols"
              :key="index"
              :label="item.label"
              :prop="item.prop"
              :show-overflow-tooltip="item.showOverflowTooltip"
              :width="item.width"
              :formatter="item.formatFunc"
              :sortable="item.sortable"
            />
            <el-table-column fixed="right" label="操作" width="60">
              <template slot-scope="scope">
                <table-button-view :id="scope.row.id" :page-code="pageCode" />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <list-pager
          :page-num="pageInfo.pageNum"
          :page-size="pageInfo.pageSize"
          :page-total="pageTotal"
        />
      </el-card>
      <detail ref="detail" @ok="handleDetailSave" />
    </el-main>
  </el-container>
</template>

<script>
import { listMixin } from '@/mixin/listMixin'
import Detail from './detail'

const MODULE_CODE = 'system'
const ENTITY_TYPE = 'log'
export default {
  name: ENTITY_TYPE,
  components: { Detail },
  mixins: [listMixin],
  data() {
    return {
      entityType: ENTITY_TYPE,
      moduleCode: MODULE_CODE,
      // eslint-disable-next-line no-eval
      api: eval('this.$api.' + MODULE_CODE + '.' + ENTITY_TYPE),
      pageCode: MODULE_CODE + ':' + ENTITY_TYPE + ':',
      queryCondition: {},
      sortInfo: {
        sort_field: 'requestTime',
        sort_sortType: 'descending'
      },
      columnList: [
        // prop label show 必须定义， width/showOverflowTooltip/formatFunc/sortable 需要的话定义
        { prop: 'content', label: '内容', show: true, showOverflowTooltip: true },
        { prop: 'operatorName', label: '姓名', show: true },
        { prop: 'operatorAccount', label: '账号', show: true },
        { prop: 'operatorIp', label: 'ip', show: true },
        { prop: 'requestTime', label: '请求时间', show: true, formatFunc: this.tableDateFormatter.formatTime, showOverflowTooltip: true },
        { prop: 'requestPath', label: '请求路径', show: true, showOverflowTooltip: true },
        { prop: 'requestMethod', label: '请求方法', show: true },
        { prop: 'logTypeName', label: '日志类型', show: true },
        { prop: 'responseCodeName', label: '是否执行成功', show: true },
        { prop: 'timeConsuming', label: '执行耗时\n(毫秒)', show: true }
      ]
    }
  },
  methods: {

  }
}
</script>

<style lang="scss" scoped>
.tab-container {
  $item-width: 200px;
  padding: 15px;
  .aside {
    min-width: 180px;
    background-color: white;
  }
  .main {
    .main-search {
      .form-item {
        width: $item-width;
      }
    }
    .main-report {
      margin-top: 10px;
    }
  }
}
</style>
